package ${package.Controller};

import ${package.Entity}.${table.entityName};
import ${package.Service}.I${table.entityName}Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import com.qianya.model.common.BaseController;
import com.qianya.model.common.CommonResult;
import com.qianya.model.common.ResultCode;
import com.qianya.model.pojo.<#if package.ModuleName??>${package.ModuleName}</#if>.qo.${table.entityName}QO;
import com.qianya.model.pojo.<#if package.ModuleName??>${package.ModuleName}</#if>.vo.${table.entityName}VO;
<#if restControllerStyle>
    import org.springframework.web.bind.annotation.RestController;
<#else>
    import org.springframework.stereotype.Controller;
</#if>
/**
* <p>
    * ${table.comment!} 前端控制器
    * </p>
*
* @author ${author}
* @since ${date}
*/
<#if restControllerStyle>
    @RestController
<#else>
    @Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
@Api(value = "${table.controllerName}", tags = "${table.comment!}接口")
@Slf4j
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
public class ${table.controllerName} {


    @Autowired
    private I${table.entityName}Service ${table.entityName?uncap_first}Service;

    @PutMapping(value = "/update")
    @ApiOperation("修改${table.comment!}")
    public CommonResult update(@RequestBody  ${table.entityName}QO ${table.entityName?uncap_first}QO){
        ${table.entityName} ${table.entityName?uncap_first} = new ${table.entityName}();
        BeanUtils.copyProperties(${table.entityName?uncap_first}QO,${table.entityName?uncap_first});
        return ${table.entityName?uncap_first}Service.renewal(${table.entityName?uncap_first});
    }
    @PostMapping(value = "/save")
    @ApiOperation("添加${table.comment!}")
    public CommonResult save(@RequestBody  ${table.entityName}QO ${table.entityName?uncap_first}QO){
        ${table.entityName} ${table.entityName?uncap_first} = new ${table.entityName}();
        BeanUtils.copyProperties(${table.entityName?uncap_first}QO,${table.entityName?uncap_first});
        return ${table.entityName?uncap_first}Service.create(${table.entityName?uncap_first});
    }

    @ApiOperation("查找${table.comment!}")
    @GetMapping(value = "/find")
    public CommonResult<IPage<${table.entityName}VO>> find(${table.entityName}QO ${table.entityName?uncap_first}QO){
        ${table.entityName} ${table.entityName?uncap_first} = new ${table.entityName}();
        BeanUtils.copyProperties(${table.entityName?uncap_first}QO,${table.entityName?uncap_first});
        return ${table.entityName?uncap_first}Service.find(${table.entityName?uncap_first});
    }

    }
    </#if>
